<template>
  <div>
    <el-dialog
      title="修改密码"
      :visible.sync="dialogVisible"
      width="20%"
    >
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="新密码" prop="password">
          <el-input v-model="form.password" show-password></el-input>
        </el-form-item>
        <!--        <el-form-item label="确认密码" prop="checkPassword">-->
        <!--          <el-input v-model="form.checkPassword" show-password></el-input>-->
        <!--        </el-form-item>-->
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="handleEdit">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
  import {updatePassword} from "@/api/sales";

  export default {
    name: "changePassw",
//     props:{
// ids:ids
//     },
    data() {
      // let validatePass = (rule, value, callback) => {
      //   if (value === '') {
      //     callback(new Error('请输入密码'));
      //   } else {
      //     if (this.form.checkPassword !== '') {
      //       this.$refs.form.validateField('checkPassword');
      //     }
      //     callback();
      //   }
      // };
      // let validatePass2 = (rule, value, callback) => {
      //   if (value === '') {
      //     callback(new Error('请再次输入密码'));
      //   } else if (value !== this.form.password) {
      //     callback(new Error('两次输入密码不一致!'));
      //   } else {
      //     callback();
      //   }
      // };
      return {
        dialogVisible: false,
        form: {
          id: '',
          password: '',
          // checkPassword: ''
        },
        // rules: {
        //   password: [
        //     {validator: validatePass, trigger: 'blur'},
        //   ],
        //   checkPassword: [
        //     {validator: validatePass2, trigger: 'blur'}
        //   ]
        // }
      }
    },
    methods: {
      show(id) {
        this.form.id = ''
        this.form.password = ''
        // this.form.checkPassword = ''
        this.form.id = id
        this.dialogVisible = true
      },
      handleEdit() {
        updatePassword(this.form).then(res => {
          if (res.status === 200) {
            this.$message.success("修改成功")
            this.dialogVisible = false
          }
        })
        // this.$refs['form'].validate((valid) => {
        //   if (valid) {
        //     updatePassword(this.form).then(res => {
        //       if (res.status === 200) {
        //         this.$message.success("修改成功")
        //         this.dialogVisible = false
        //       }
        //     })
        //   } else {
        //     return false;
        //   }
        // });
      }
    }
  }
</script>

<style scoped>

</style>
